﻿using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using MuseumApp315.Data.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity.Migrations;

namespace MuseumApp315.Data
{
    public static class Seeder
    {
        public static void Seed(ApplicationDbContext db)
        {
            // generic Identity - Store the users
            UserStore<ApplicationUser> userStore = new UserStore<ApplicationUser>(db);
            UserManager<ApplicationUser> userManager = new UserManager<ApplicationUser>(userStore);

            // generic Identity - roles
            RoleStore<Role> roleStore = new RoleStore<Role>(db);
            RoleManager<Role> roleManager = new RoleManager<Role>(roleStore);

            // seed data users...
            ApplicationUser userOne = null;
            userOne = userManager.FindByName("julio@codercamps.com");

            // if USER_ONE does not exist, do create them
            if (userOne == null)
            {
                userManager.Create(new ApplicationUser
                {
                    Email = "julio@codercamps.com",
                    FirstName = "julio",
                    LastName = "r",
                    UserName = "julio@codercamps.com"
                }, "123456");
                userOne = userManager.FindByName("julio@codercamps.com");
            }

            ApplicationUser userTwo = null;
            userTwo = userManager.FindByName("rickjames@codercamps.com");
            // if USER_TWO does not exist, do create them
            if (userTwo == null)
            {
                userManager.Create(new ApplicationUser
                {
                    Email = "rickjames@codercamps.com",
                    FirstName = "Rick",
                    LastName = "J",
                    UserName = "rickjames@codercamps.com"
                }, "123456");
                userTwo = userManager.FindByName("rickjames@codercamps.com");
            }



            // if ROLES does not exist, do create them
            if (!roleManager.Roles.Any())
            {
                roleManager.Create(new Role { Name = "Admin" });
                roleManager.Create(new Role { Name = "General" });
            }

            // assign the userOne into a role
            if (!userManager.IsInRole(userOne.Id, "Admin"))
            {
                userManager.AddToRole(userOne.Id, "Admin");
            }
            // assign the userOne into a role
            if (!userManager.IsInRole(userTwo.Id, "General"))
            {
                userManager.AddToRole(userTwo.Id, "General");
            }


            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );

            // Seed the museums...
            if (!db.Museums.Any())
            {
                db.Museums.AddOrUpdate(new Museum() { MuseumId = 1, Name = "Fine Art", City = "Dallas", Description = "Art that is fine" });
                db.Museums.AddOrUpdate(new Museum() { MuseumId = 2, Name = "Modern Art", City = "Houston", Description = "Madern Art that is new" });
                db.Museums.AddOrUpdate(new Museum() { MuseumId = 3, Name = "Sculpture Garden", City = "Austin", Description = "Large arbstract sculptures" });
            }
            // Seed the Reviews...
            if (!db.Reviews.Any())
            {
                db.Reviews.Add(new Review() { ReviewId = 1, UserName = userOne.UserName, MuseumId = 1, Rating = 5, Comment = "They had the picasos" });
                db.Reviews.Add(new Review() { ReviewId = 2, UserName = userTwo.UserName, MuseumId = 1, Rating = 8, Comment = "Exit through the gift shop" });
                db.Reviews.Add(new Review() { ReviewId = 3, UserName = userOne.UserName, MuseumId = 2, Rating = 7, Comment = "Very modern" });
                db.Reviews.Add(new Review() { ReviewId = 4, UserName = userOne.UserName, MuseumId = 3, Rating = 2, Comment = "Very hot day " });

            }
            // Seed the Tags...
            if (!db.Tags.Any())
            {
                db.Tags.Add(new Tag() { TagId = 1, Name = "picaso" });
                db.Tags.Add(new Tag() { TagId = 2, Name = "MOMA" });
                db.Tags.Add(new Tag() { TagId = 3, Name = "canvas" });
                db.Tags.Add(new Tag() { TagId = 4, Name = "sculptures" });
                db.Tags.Add(new Tag() { TagId = 5, Name = "indoors" });
            }
            // Seed the MuseumTags...
            if (!db.MuseumTags.Any())
            {
                db.MuseumTags.Add(new MuseumTags() { MuseumTagsId = 1, MuseumId = 1, TagId = 1 });
                db.MuseumTags.Add(new MuseumTags() { MuseumTagsId = 4, MuseumId = 1, TagId = 3 });
                db.MuseumTags.Add(new MuseumTags() { MuseumTagsId = 2, MuseumId = 1, TagId = 3 });
                db.MuseumTags.Add(new MuseumTags() { MuseumTagsId = 3, MuseumId = 3, TagId = 4 });
                db.MuseumTags.Add(new MuseumTags() { MuseumTagsId = 5, MuseumId = 2, TagId = 5 });
                db.MuseumTags.Add(new MuseumTags() { MuseumTagsId = 6, MuseumId = 3, TagId = 4 });
                db.MuseumTags.Add(new MuseumTags() { MuseumTagsId = 7, MuseumId = 3, TagId = 4 });
            }
            



        }
    }
}
